/**
 * @Author: wzx
 * @Description:
 * @Version: 1.0.0
 * @Date: 2021/5/20 上午1:08
 *@Copyright: MIN-Group；国家重大科技基础设施——未来网络北大实验室；深圳市信息论与未来网络重点实验室
 */
package router

import (
	"context"
	"vpn-management-server/network"
	"vpn-management-server/src/interceptor/authinterceptor"
	"vpn-management-server/src/router/adminlogrouter"
	"vpn-management-server/src/router/adminrouter"
	"vpn-management-server/src/router/analysisrouter"
	"vpn-management-server/src/router/rgrouprouter"
	"vpn-management-server/src/router/rulerouter"
	"vpn-management-server/src/router/testrouter"
	"vpn-management-server/src/router/ugrouprouter"
	"vpn-management-server/src/router/userlogrouter"
	"vpn-management-server/src/router/userrouter"
	"vpn-management-server/src/router/vpnrouter"
	"vpn-management-server/src/router/whitelistrouter"
)

type TypeRouter func(ctx context.Context, request *network.NetRequest, response *network.NetResponse)

type BeforeRouter func(ctx context.Context, request *network.NetRequest, response *network.NetResponse) bool

type AfterRouter func(ctx context.Context, request *network.NetRequest, response *network.NetResponse)

type routers struct {
	beforeRouter map[string]BeforeRouter
	typeRouters  map[string]TypeRouter
	afterRouter  map[string]AfterRouter
}

func NewRouters() *routers {
	return &routers{
		beforeRouter: make(map[string]BeforeRouter),
		typeRouters:  make(map[string]TypeRouter),
		afterRouter:  make(map[string]AfterRouter),
	}
}

func (routers *routers) AddTypeRouter(name string, beforeRouter BeforeRouter, typeRouter TypeRouter, afterRouter AfterRouter) {
	routers.beforeRouter[name] = beforeRouter
	routers.typeRouters[name] = typeRouter
	routers.afterRouter[name] = afterRouter
}

var gRouters = NewRouters()

func init() {
	gRouters.AddTypeRouter("vpn", authinterceptor.VpnAuthSession, vpnrouter.VpnRouter, nil)
	gRouters.AddTypeRouter("analysis", authinterceptor.AuthSession, analysisrouter.AnalysisRouter, nil)
	gRouters.AddTypeRouter("user", authinterceptor.UserAuthSession, userrouter.UserRouter, nil)
	gRouters.AddTypeRouter("ugroup", authinterceptor.AuthSession, ugrouprouter.UGroupRouter, nil)
	gRouters.AddTypeRouter("admin", authinterceptor.AuthSession, adminrouter.AdminRouter, nil)
	gRouters.AddTypeRouter("whitelist", authinterceptor.AuthSession, whitelistrouter.WhitelistRouter, nil)
	gRouters.AddTypeRouter("adminLog", authinterceptor.AuthSession, adminlogrouter.AdminLogRouter, nil)
	gRouters.AddTypeRouter("userLog", authinterceptor.UserLogAuthSession, userlogrouter.UserLogRouter, nil)
	gRouters.AddTypeRouter("rule", authinterceptor.RuleAuthSession, rulerouter.RuleRouter, nil)
	gRouters.AddTypeRouter("rgroup", authinterceptor.AuthSession, rgrouprouter.RGroupRouter, nil)
	gRouters.AddTypeRouter("test", authinterceptor.AuthSession, testrouter.TestRouter, nil)
}
